package com.xue.domain;

import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xue
 * @create 2022-09-21 11:12
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class StaticLocationResponseInfo extends Info {

    private String idArray;

    private String coordinateXArray;

    private String coordinateYArray;

    private List<LocationInfo> list;

    @Override
    public Info decoding(ByteBuf content) {
        StaticLocationResponseInfo instance = (StaticLocationResponseInfo) super.decoding(content);
        String[] ids = instance.getIdArray().split(",");
        String[] xS = instance.getCoordinateXArray().split(",");
        String[] yS = instance.getCoordinateYArray().split(",");
        int len = ids.length;
        List<LocationInfo> instanceList = new ArrayList<>();
        for (int i = 0; i < len; i++) {
            instanceList.add(new LocationInfo(2, ids[i], Double.parseDouble(xS[i]), Double.parseDouble(yS[i])));
        }
        instance.setList(instanceList);
        return instance;
    }

    @Override
    public Integer getInfoType() {
        return STATIC_LOCATION_INFO_RESPONSE;
    }
}
